<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="关键字" prop="val">
        <el-input
          v-model="queryParams.val"
          placeholder="请输入关键字搜索"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指导单位" prop="college">
        <el-select v-model="queryParams.college" placeholder="请选择" clearable size="small">
          <el-option
            v-for="(dict, index) in unitNameList"
            :key="index"
            :label="dict.sponsorName"
            :value="dict.sponsorName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="调研主题" prop="researchtopic">
        <el-select v-model="queryParams.researchtopic" placeholder="请选择" clearable size="small">
          <el-option
            v-for="(dict, index) in researchtopics"
            :key="index"
            :label="dict.optionName"
            :value="dict.optionName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否重点" prop="isimportant">
        <el-select v-model="queryParams.isimportant" placeholder="请选择" clearable size="small">
          <el-option
            v-for="(dict, index) in isimportants"
            :key="index"
            :label="dict.optionName"
            :value="dict.optionId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="成果形式" prop="presentation">
        <el-select v-model="queryParams.presentation" placeholder="请选择" clearable size="small">
          <el-option
            v-for="(dict, index) in presentationOptions"
            :key="index"
            :label="dict.optionName"
            :value="dict.optionName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间" prop="searchTime">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.searchTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="地点" prop="searchPlace">
        <el-input
          v-model="queryParams.searchPlace"
          placeholder="请输入地点搜索"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option label="创建" value="0"></el-option>
          <el-option label="待指导教师审批" value="3"></el-option>
          <el-option label="待指导单位审批" value="4"></el-option>
          <el-option label="待学校团委审批" value="5"></el-option>
          <el-option label="通过" value="6"></el-option>
          <el-option label="驳回" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学期" prop="schoolYear">
          <el-select v-model="queryParams.schoolYear" placeholder="请选择学期">
            <el-option
              v-for="option in schoolYears"
              :key="option.schoolYearId"
              :label="option.schoolYearId"
              :value="option.schoolYearId"
            />
          </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['eqxm:team:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['eqxm:team:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['eqxm:team:remove']"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['eqxm:team:export']"
          >导出团队基本信息</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          style="padding: 8px; margin-right: 8px"
          size="mini"
          type="primary"
          v-hasPermi="['eqxm:stuManage:college']"
          @click="stuManage(1)"
          >本单位团队打卡提醒</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          style="padding: 8px; margin-right: 8px"
          size="mini"
          type="primary"
          v-hasPermi="['eqxm:stuManage:school']"
          @click="stuManage(2)"
          >全校打卡提醒</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          style="padding: 8px; margin-right: 8px"
          size="mini"
          type="primary"
          v-hasPermi="['eqxm:stuManage:collegeExport']"
          @click="clockExport(1)"
          >导出本单位打卡</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          style="padding: 8px; margin-right: 8px"
          size="mini"
          type="primary"
          v-hasPermi="['eqxm:stuManage:schoolExport']"
          @click="clockExport(2)"
          >导出全校打卡</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          style="padding: 8px; margin-right: 8px"
          size="mini"
          type="primary"
          v-hasPermi="['eqxm:stuManage:sendTotal']"
          @click="sendclockInfo"
          >发送打卡数据汇总</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          style="padding: 8px; margin-right: 8px"
          size="mini"
          type="primary"
          v-hasPermi="['eqxm:stuManage:exportMan']"
          @click="exportMan"
          >导出成员信息</el-button
        >
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 顶部滚动条 -->
    <div ref="topScroll" class="top-scroll">
      <div class="top-scroll-content" :style="{ width: topScrollWidth }"></div>
    </div>
    <!-- :span-method="objectSpanMethod" -->
    <el-table
      v-loading="loading"
      border
      :data="teamList"
      @selection-change="handleSelectionChange"
      ref="tableRef"
    >
      <el-table-column type="index" label="序号" width="60" align="center" />
      <el-table-column label="团队名称" align="center" prop="name" />
      <el-table-column label="负责人" align="center">
        <template slot-scope="scope">
          <div
            style="border-bottom: 1px solid #ddd"
            v-for="(val, index) in scope.row.eqxmTeamStudentList"
            :key="index"
            v-show="val.role == '1'"
          >
            <div>{{ val.name }}-{{ val.username + '\n' }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="指导单位" align="center" prop="college" />
      <el-table-column label="调研主题" align="center" prop="researchtopic"></el-table-column>
      <el-table-column label="重点团队" align="center" prop="isimportantName" />
      <!-- <template slot-scope="scope"> -->
      <el-table-column label="时间" align="center" width="120">
        <template slot-scope="scope">
          <div
            style="border-bottom: 1px solid #ddd"
            v-for="(val, index) in scope.row.eqxmTeamPlaceList"
            :key="index"
          >
            <div>{{ val.starttime }}—{{ val.endtime + '\n' }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="地点" align="center" width="230">
        <template slot-scope="scope">
          <div
            style="border-bottom: 1px solid #ddd"
            v-for="(val, index) in scope.row.eqxmTeamPlaceList"
            :key="index"
          >
            <div>{{ val.provincial + '\n' }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" :formatter="statusFormat" align="center" prop="status">
        <template slot-scope="scope">
          <!-- <el-tooltip placement="top">
            <div slot="content">多行信息<br />第二行信息</div>
            <el-button></el-button>
          </el-tooltip> -->
          <el-popover placement="bottom" width="500" trigger="click">
            <div>
              <div v-if="scope.row.status == 0">请填写完整后提交！</div>
              <div v-if="scope.row.status == 3">指导教师暂未审核！</div>
              <el-card v-if="scope.row.commentsOne" class="box-card">
                <div slot="header" class="clearfix">
                  <span>指导教师意见</span>
                </div>
                <!-- <div v-html="imgStyle(scope.row.commentsOne)"></div> -->
                <div>{{ scope.row.commentsOne }}</div>
              </el-card>
              <el-card v-if="scope.row.commentsTwo" class="box-card" style="margin-top: 10px">
                <div slot="header" class="clearfix">
                  <span>指导单位意见</span>
                </div>
                <!-- <div v-html="imgStyle(scope.row.commentsTwo)"></div> -->
                <div>{{ scope.row.commentsTwo }}</div>
              </el-card>
              <el-card v-if="scope.row.commentsThree" class="box-card" style="margin-top: 10px">
                <div slot="header" class="clearfix">
                  <span>学校团委意见</span>
                </div>
                <!-- <div v-html="imgStyle(scope.row.commentsThree)"></div> -->
                <div>{{ scope.row.commentsThree }}</div>
              </el-card>
            </div>
            <el-button type="text" slot="reference">
              <dict-tag :options="dict.type.team_status" :value="scope.row.status"
            /></el-button>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="打卡记录" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <span>
            {{ scope.row.clockCount }}/{{scope.row.studentCount * 1 + scope.row.teacherCount * 1}}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300"
      >
        <template
          slot-scope="scope"
          v-if="administrators(scope.row) || canWrite(scope.row) || judgeRole(scope.row)"
        >
          <el-button
            style="padding: 8px; margin-bottom: 8px"
            size="mini"
            type="primary"
            class="tag-read"
            icon="el-icon-document-copy"
            :data-clipboard-text="'https://erke.hdu.edu.cn/weixin/#/pages/index/practice/audit?id=' + scope.row.id"
            @click="audit(scope.row)"
            v-hasPermi="['eqxm:teamDetail:query']"
            >审核链接</el-button
          >
          <el-button
            style="padding: 8px; margin-bottom: 8px"
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['eqxm:teamDetail:query']"
            >详情</el-button
          >
          <el-button
            style="padding: 8px"
            size="mini"
            type="primary"
            icon="el-icon-upload"
            @click="upload(scope.row)"
            v-hasPermi="['eqxm:meterial:query']"
            >上传材料</el-button
          >
          <!-- <el-button
            v-if="scope.row.status == '0' || scope.row.status == '2'"
            size="mini"
            type="text"
            @click="commitExamine(scope.row)"
            v-hasPermi="['eqxm:team:remove']"
            >提交审核</el-button
          > -->
          <el-button
            style="padding: 8px"
            size="mini"
            type="primary"
            @click="openclock(scope.row)"
            v-hasPermi="['eqxm:clockdetail:query']"
            >打卡详情</el-button
          >
          <el-button
            style="padding: 8px"
            size="mini"
            type="primary"
            @click="sendclockMsg(scope.row)"
            v-hasPermi="['eqxm:clockdetail:sendclock']"
            v-if="scope.row.status == 6 && canWrite(scope.row)"
            >打卡提醒</el-button
          >
          <el-button
            style="padding: 8px"
            type="danger"
            size="mini"
            v-hasPermi="['eqxm:team:remove']"
            @click="handleDelete(scope.row.id, scope.row.name)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="handleQuery2"
    />

    <!-- 添加或修改团队对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="指导单位" prop="college">
          <el-input v-model="form.college" placeholder="请输入指导单位" />
        </el-form-item>
        <el-form-item label="调研主题" prop="researchtopic">
          <el-input v-model="form.researchtopic" placeholder="请输入调研主题" />
        </el-form-item>
        <el-form-item label="是否重点" prop="isimportant">
          <el-input v-model="form.isimportant" placeholder="请输入是否重点" />
        </el-form-item>
        <el-form-item label="呈现形式" prop="presentation">
          <el-input v-model="form.presentation" placeholder="请输入呈现形式" />
        </el-form-item>
        <el-form-item label="呈现形式详情" prop="presentationdetail">
          <el-input v-model="form.presentationdetail" placeholder="请输入呈现形式详情" />
        </el-form-item>
        <el-form-item label="交通费" prop="transportation">
          <el-input v-model="form.transportation" placeholder="请输入交通费" />
        </el-form-item>
        <el-form-item label="住宿费" prop="accommodation">
          <el-input v-model="form.accommodation" placeholder="请输入住宿费" />
        </el-form-item>
        <el-form-item label="宣传费" prop="publicity">
          <el-input v-model="form.publicity" placeholder="请输入宣传费" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 打卡详情 -->
    <el-dialog title="打卡详情" :visible.sync="clockopen" width="1000px" append-to-body>
      <el-form :inline="true" ref="clockform" :model="clockform" :rules="rules" label-width="80px">
        <!-- <el-form-item label="调研主题" prop="researchtopic">
        <el-select v-model="clockform.researchtopic" placeholder="请选择" clearable size="small">
          <el-option
            v-for="(dict, index) in researchtopics"
            :key="index"
            :label="dict.optionName"
            :value="dict.optionId"
          />
        </el-select>
      </el-form-item> -->
        <el-form-item label="时间" prop="time">
          <el-date-picker
            clearable
            size="small"
            v-model="clockform.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="1">导出未打卡</el-button>
        </el-form-item>
      </el-form>
      <el-table border :data="clockdetailList">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="学号" align="center" prop="username" />
        <el-table-column label="团队名称" align="center" prop="teamname" />
        <el-table-column label="调研主题" align="center" prop="researchtopic" />
        <el-table-column label="地点" align="center" prop="place" />
        <el-table-column label="时间" align="center" prop="createTime" />
        <el-table-column label="状态" align="center" class-name="small-padding fixed-width">
          已打卡
          <!-- <template slot-scope="scope">
            <span v-if="scope.row.id == null || scope.row.id == ''">未打卡</span>
            <span v-if="!(scope.row.id == null || scope.row.id == '')">已打卡</span>
          </template> -->
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 设置指导单位学校负责人 -->
    <el-dialog :title="title" :visible.sync="stuManageOpen" width="500px" append-to-body>
      <el-form ref="stuForm" :model="stuForm" :rules="rules" label-width="100px">
        <el-form-item label="学生管理员" prop="studentId">
          <el-select
            v-model="stuForm.studentId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod"
            :loading="searchLoading"
          >
            <el-option
              v-for="item in options"
              :key="item.xh"
              :label="item.xh + '-' + item.xm"
              :value="item.xh"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="stuManageSubmit">确 定</el-button>
        <el-button @click="stuManagecancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTeam,
  getTeam,
  delTeam,
  addTeam,
  updateTeam,
  exportTeam,
  ispass,
  sendclock,
  sendclock2,
  sendclock3,
  sendclock1,
  exportTeamMember,
  getstudentmanager,
  setPrincipal,
  listPrincipal,
  GetYearList
} from '@/api/eqxm/team';
import { listSponsor } from "@/api/system/sponsor";
import { teamStatusMap, teamStatusOptions } from '@/views/eqxm/enum';
import { listOption } from '@/api/system/option';
import CommonUtils from '@/utils/CommonUtils';
import {
  listClockdetail,
  getClockdetail,
  delClockdetail,
  addClockdetail,
  updateClockdetail,
  exportClockdetail,
} from '@/api/eqxm/clockdetail';
import { Message,Loading } from 'element-ui';
import { mapGetters } from 'vuex';
import Clipboard from 'clipboard';
export default {
  name: 'Team',
  dicts: ['team_status'],
  components: {},
  computed: {
    ...mapGetters(['roles', 'name','unitName']),
  },
  filters: {
    teamStatusMap: function (value) {
      return teamStatusMap.get(value);
    },
  },
  created() {
    this.getYearList().then(()=>{
      this.getList()
    })
    
    listSponsor().then(response => {
      this.unitNameList = response.rows;
      console.log(response, '111');
    });
    listOption({ optionType: 1 }).then(response => {
      this.researchtopics = response.rows;
    });
    listOption({ optionType: 2 }).then(response => {
      this.presentationOptions = response.rows;
    });
    listOption({ optionType: 3 }).then(response => {
      this.isimportants = response.rows;
    });
    listPrincipal({ principalId: this.name }).then(response => {
      this.userPrincipal = response.rows;
    });

    // let newform = {
    //   teamid: '12',
    // };
    // sendclock(newform).then(response => {
    //   console.log(66666666, response);
    // });

    //转换树形结构的数据，⽤来⽅便拆分合并单元格
    // this.tableData = []
    // this.teamList.forEach(i => {
    //   if (i.eqxmTeamPlaceList) {
    //     i.eqxmTeamPlaceList.forEach(j => {
    //       j.parentId = i.id
    //     })
    //   }
    //   if (i.eqxmTeamPlaceList) {
    //     this.tableData.push(...i.eqxmTeamPlaceList)
    //   } else {
    //     this.tableData.push(i)
    //   }
    // })
    // this.getList();
    
  },
  data() {
    return {
      topScrollWidth: 0,
      tableDom: null,
      // 遮罩层
      loading: true,
      clockopen: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      tableData: [],
      // 团队表格数据
      teamList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      stuManageOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        college: null,
        researchtopic: null,
        isimportant: null,
        presentation: null,
        presentationdetail: null,
        transportation: null,
        accommodation: null,
        publicity: null,
        schoolYear:null
      },
      clockform: {},
      //普通学生是否团队学生
      isTeamStu: null,
      // 学生列表
      options: [],
      searchLoading: false,
      // 表单参数
      form: {},
      stuForm: {
        studentId: '',
        roleId: '',
      },
      // 表单校验
      rules: {},
      unitNameList: [],
      isimportants: [],
      presentationOptions: [],
      researchtopics: [],
      clockdetailList: [],
      userPrincipal: [],
      schoolYears:[],
    };
  },

  watch: {
    topScrollWidth: {
      // 两个滚动条同时滚动
      handler(newVal, oldVal) {
        // 监听滚动条
        this.$nextTick(() => {
          this.tableDom = this.$refs.tableRef.bodyWrapper;
          this.tableDom.addEventListener('scroll', () => {
            // 表格顶部滚动条与底部同步
            let scrollLeft = this.tableDom.scrollLeft;
            this.$refs.topScroll.scrollTo(scrollLeft, 0);
          });
          let topScroll = this.$refs.topScroll;
          topScroll.addEventListener('scroll', () => {
            // 表格底部滚动条与顶部同步
            let scrollLeft = topScroll.scrollLeft;
            this.tableDom.scrollTo(scrollLeft, 0);
          });
        });
      },
      deep: true,
    },
  },

  methods: {
    getYearList(){
      GetYearList().then(response=>{
        console.log(response);
        this.schoolYears = response.rows;
        for (let i = 0; i < response.total; i++) {
          if (response.rows[i].defaultValue == '1') {
            this.queryParams.schoolYear = response.rows[i].schoolYearId;
          }
        }
      })
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const parent = this.teamList.find(i => i.id === row.parentId);
        console.log(row, parent, '`111342342');
        // if (parent && row.teamid === parent.eqxmTeamPlaceList[0].teamid) {
        //   console.log(parent.eqxmTeamPlaceList.length,"333")
        return {
          rowspan: 3, //parent.eqxmTeamPlaceList.length,
          colspan: 1,
        };
        // } else if (parent && row.teamid !== parent.eqxmTeamPlaceList[0].teamid) {
        //   return {
        //     rowspan: 0,
        //     colspan: 0,
        //   };
        // }
      }
    },
    // 审核
    audit(row){
      console.log(row);
      var clipboard = new Clipboard('.tag-read');
      clipboard.on('success', e => {
        console.log('复制成功');
        this.$modal.msgSuccess('职位审核链接' + '复制成功');
        // 释放内存
        clipboard.destroy();
      });
      clipboard.on('error', e => {
        // 不支持复制
        console.log('该浏览器不支持自动复制');
        this.$modal.msgError("该浏览器不支持自动复制");
        // 释放内存
        clipboard.destroy();
      });
    },
    // /** 查询团队列表 */
    getList() {
      this.loading = true;
      // this.queryParams.stuOrTeacherId = this.name;
      if (localStorage.getItem('teamQueryParams')) {
        var pageNum = this.queryParams.pageNum;
        this.queryParams = JSON.parse(localStorage.getItem('teamQueryParams'));
        this.queryParams.pageNum = pageNum;
      }
      // this.queryParams.schoolYear = this.queryParams.schoolYear;
      console.log(this.queryParams.schoolYear);
      listTeam(this.queryParams).then(response => {
        console.log(response, 'teamres');

        for (let i = 0; i < response.total; i++) {
          // var str = response.rows[i].commentsOne
          // var reg = new RegExp("<p>")
          if (response.rows[i]) {
            response.rows[i].commentsOne = response.rows[i].commentsOne
              ? response.rows[i].commentsOne.replace('<p>', '')
              : '';
            response.rows[i].commentsOne = response.rows[i].commentsOne
              ? response.rows[i].commentsOne.replace('</p>', '')
              : '';
            response.rows[i].commentsTwo = response.rows[i].commentsTwo
              ? response.rows[i].commentsTwo.replace('<p>', '')
              : '';
            response.rows[i].commentsTwo = response.rows[i].commentsTwo
              ? response.rows[i].commentsTwo.replace('</p>', '')
              : '';
            response.rows[i].commentsThree = response.rows[i].commentsThree
              ? response.rows[i].commentsThree.replace('<p>', '')
              : '';
            response.rows[i].commentsThree = response.rows[i].commentsThree
              ? response.rows[i].commentsThree.replace('</p>', '')
              : '';
          }
          if (
            response.rows[i] &&
            response.rows[i].eqxmTeamPlaceList &&
            response.rows[i].eqxmTeamPlaceList != []
          ) {
            for (let j = 0; j < response.rows[i].eqxmTeamPlaceList.length; j++) {
              let provincial = response.rows[i].eqxmTeamPlaceList[j].provincial;
              let starttime = response.rows[i].eqxmTeamPlaceList[j].starttime;
              let endtime = response.rows[i].eqxmTeamPlaceList[j].endtime;
              var a = provincial.indexOf('区');
              if (a == -1) {
                a = provincial.indexOf('市');
              }
              if (a != -1) {
                response.rows[i].eqxmTeamPlaceList[j].provincial = provincial.substring(0, a + 1);
              }
              // response.rows[i].eqxmTeamPlaceList[j].provincial = provincial.substring(0, a + 1);
              let t = starttime.indexOf('-');
              response.rows[i].eqxmTeamPlaceList[j].starttime = starttime.substring(
                t + 1,
                starttime.length
              );
              response.rows[i].eqxmTeamPlaceList[j].endtime = endtime.substring(
                t + 1,
                endtime.length
              );
            }
          }
        }
        this.teamList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.setScrollWidth();

        // this.tableData = [];
        // this.teamList.forEach(i => {
        //   if (i.eqxmTeamPlaceList) {
        //     i.eqxmTeamPlaceList.forEach(j => {
        //       j.parentId = i.id;
        //     });
        //   }
        //   if (i.eqxmTeamPlaceList) {
        //     this.tableData.push(...i.eqxmTeamPlaceList);
        //   } else {
        //     this.tableData.push(i);
        //   }
        // });
        // console.log(this.teamList, this.tableData, '111');
      });
    },
    // 该方法在获取列表数据后调用
    setScrollWidth() {
      console.log(this.topScrollWidth, 'this.topScrollWidth1');
      //设置顶部滚顶条宽度值为表格的滚动宽度
      this.$nextTick(() => {
        this.topScrollWidth = this.$refs.tableRef.bodyWrapper.scrollWidth + 'px';
        console.log(this.topScrollWidth, 'this.topScrollWidth');
      });
    },
    // 判断角色
    judgeRole(row) {
      var isTeamStu = false;
      var commonStu = false;
      // for (let i = 0; i < this.roles.length; i++) {
      //   if (this.roles[i] == 'common-student') {
      //     commonStu = true;
      //   } else {
      //     isTeamStu = true;
      //   }
      // }
      if (row.eqxmTeamStudentList) {
        for (let i = 0; i < row.eqxmTeamStudentList.length; i++) {
          if (row.eqxmTeamStudentList[i].username == this.name) isTeamStu = true;
        }
      }
      return isTeamStu;
    },
    administrators(row) {
      var isCanWrite = false;
      if (this.roles) {
        for (let i = 0; i < this.roles.length; i++) {
          if (
            this.roles[i] == 'student-school' ||
            this.roles[i] == 'common' ||
            this.roles[i] == 'admin'
          ) {
            isCanWrite = true;
            break;
          }
          if (this.roles[i] == 'student-college' || this.roles[i] == 'teacher3') {
            if (this.unitName == row.college) {
              isCanWrite = true;
              break;
            }
          }
          if (this.roles[i] == 'practice-responsible' && this.userPrincipal) {
            for (let i = 0; i < this.userPrincipal.length; i++) {
              if (this.userPrincipal[i].sponsorName == row.college) {
                isCanWrite = true;
                break;
              }
            }
          }
        }
      }
      return isCanWrite;
    },
    // 判断是否能发送打卡提醒
    canWrite(row) {
      console.log(row);
      var isCanWrite = false;
      // if (this.roles) {
      //   console.log(this.roles, 'roles');
      //   for (let i = 0; i < this.roles.length; i++) {
      //     if (
      //       this.roles[i] == 'student-school' ||
      //       this.roles[i] == 'common' ||
      //       this.roles[i] == 'admin'
      //     ) {
      //       isCanWrite = true;
      //       break;
      //     }
      //     if (this.roles[i] == 'student-college' || this.roles[i] == 'teacher3') {
      //       if (this.unitName == row.college) {
      //         isCanWrite = true;
      //         break;
      //       }
      //     }
      //     if (this.roles[i] == 'practice-responsible' && this.userPrincipal) {
      //       for (let i = 0; i < this.userPrincipal.length; i++) {
      //         if (this.userPrincipal[i] == row.college) {
      //           isCanWrite = true;
      //           break;
      //         }
      //       }
      //     }
      //   }
      // }
      if (!isCanWrite) {
        if (row.createBy == this.name) {
          isCanWrite = true;
        } else if (row.eqxmTeamTeacherList) {
          for (let i = 0; i < row.eqxmTeamTeacherList.length; i++) {
            if (row.eqxmTeamTeacherList[i].username == this.name) {
              console.log(row.eqxmTeamTeacherList[i].username == this.name, 'ddd');
              isCanWrite = true;
              break;
            }
          }
          if (!isCanWrite && row.eqxmTeamStudentList) {
            for (let i = 0; i < row.eqxmTeamStudentList.length; i++) {
              if (
                row.eqxmTeamStudentList[i].username == this.name &&
                row.eqxmTeamStudentList[i].role == 1
              ) {
                isCanWrite = true;
                break;
              }
            }
            for (let i = 0; i < row.eqxmTeamStudentList.length; i++) {
              if (
                row.eqxmTeamStudentList[i].username == this.name &&
                row.eqxmTeamStudentList[i].role == 3
              ) {
                isCanWrite = true;
                break;
              }
            }
          }
        } else if (row.eqxmTeamStudentList) {
          for (let i = 0; i < row.eqxmTeamStudentList.length; i++) {
            if (
              row.eqxmTeamStudentList[i].username == this.name &&
              row.eqxmTeamStudentList[i].role == 1
            ) {
              isCanWrite = true;
              break;
            }
          }
          for (let i = 0; i < row.eqxmTeamStudentList.length; i++) {
            if (
              row.eqxmTeamStudentList[i].username == this.name &&
              row.eqxmTeamStudentList[i].role == 3
            ) {
              isCanWrite = true;
              break;
            }
          }
        }
      }
      console.log(isCanWrite, 'isCanWrite');
      return isCanWrite;
    },
    sendclockMsg(row) {
      console.log(row);
      this.$confirm(`确定对【${row.name}】团队群发消息,提醒打卡吗？`, '提示', {
        type: 'warning',
      }).then(() => {
        let newform = {
          teamid: row.id,
          username: this.name,
        };
        sendclock(newform).then(response => {
          console.log(66666666, response);
          Message({
            message: response.data.msg,
            type: 'success',
          });
        });
      });
    },
    // 发送打卡提醒
    stuManage(num) {
      // this.stuManageOpen = true;
      // this.title = num == 1 ? '设置指导单位负责人' : '设置学校负责人';
      // this.stuForm.roleId = num == 1 ? '136' : '137';
      this.$confirm(`确定对${num == 1 ? '全院' : '全校'}团队群发消息,提醒打卡吗？`, '提示', {
        type: 'warning',
      }).then(() => {
        // let newform = {
        //   teamid: row.id,
        //   username: this.name,
        // };
        if (num == 2) {
          sendclock2().then(response => {
            console.log(66666666, response);
            Message({
              message: response.msg,
              type: 'success',
            });
          });
        } else {
          sendclock3().then(response => {
            console.log(66666666, response);
            Message({
              message: response.msg,
              type: 'success',
            });
          });
        }
      });
    },
    // 发送打卡汇总
    sendclockInfo() {
      this.$confirm(`确定发送打卡汇总吗？`, '提示', {
        type: 'warning',
      }).then(() => {
        sendclock1().then(response => {
          console.log(66666666, response);
          Message({
            message: response.msg,
            type: 'success',
          });
        });
      });
    },
    // 导出打卡
    clockExport(num) {
      this.$confirm(`确定对${num == 1 ? '全院' : '全校'}团队打卡情况进行导出？`, '提示', {
        type: 'warning',
      }).then(() => {
        if (num == 2) {
          console.log('导出全校打卡');
          this.download(
            '/eqxm/team/exportNotClock',
            { ...this.queryParams },
            `schoolExportClock_${new Date().getTime()}.xlsx`
          );
        } else {
          console.log('导出本单位打卡');
          this.download(
            '/eqxm/team/exportNotClock2',
            { ...this.queryParams },
            `exportClock_${new Date().getTime()}.xlsx`
          );
        }
      });
    },
    // 导出成员
    exportMan() {
      this.$confirm(`确定导出社会实践成员信息？`, '提示', {
        type: 'warning',
      }).then(() => {
        this.download(
            '/eqxm/team/toExcel',
            {},
            `exportMember_${new Date().getTime()}.xlsx`,
          );
        // exportTeamMember().then(response => {
        //   window.open(response);
        //   // this.download(response)
        //     console.log(66666666, response);
        //   });
      });
    },
    //设置负责人提交
    stuManageSubmit() {
      console.log(this.stuForm, '1122123123');
      let newform = {
        studentId: this.stuForm.studentId,
        roleId: this.stuForm.roleId,
      };
      console.log(newform, '1122123123888');
      setPrincipal(newform).then(response => {
        console.log(66666666, response);
        Message({
          message: response.msg,
          type: 'success',
        });
        this.stuManageOpen = false;
      });
    },
    /** 查询学生管理员 */
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        getstudentmanager(query).then(response => {
          this.loading = false;
          this.options = response.rows;
          // .filter(item => {
          //   return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          // });
        });
      } else {
        this.options = [];
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 设置管理员取消按钮
    stuManagecancel() {
      this.stuManageOpen = false;
      this.stuForm = {
        studentId: '',
        roleId: '',
      };
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        delFlag: null,
        college: null,
        createBy: null,
        researchtopic: null,
        isimportant: null,
        createTime: null,
        presentation: null,
        updateBy: null,
        presentationdetail: null,
        updateTime: null,
        transportation: null,
        accommodation: null,
        publicity: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      localStorage.setItem('teamQueryParams', JSON.stringify(this.queryParams));
      this.getList();
    },
    handleQuery2() {
      localStorage.setItem('teamQueryParams', JSON.stringify(this.queryParams));
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: null,
        college: null,
        researchtopic: null,
        isimportant: null,
        presentation: null,
        presentationdetail: null,
        transportation: null,
        accommodation: null,
        publicity: null,
      }),
        // this.resetForm('queryForm');
        localStorage.setItem('teamQueryParams', JSON.stringify(this.queryParams));
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //清空store的项目信息
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/team/teamManage', //跳转的路径
        query: { type: 0 },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      let teamInfo = {
        id: row.id,
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/team/teamManage', //跳转的路径
        query: { type: 0 },
      });
    },
    upload(row) {
      this.reset();
      let teamInfo = {
        id: row.id,
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/team/upload', //跳转的路径
        query: { type: 0 },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['submitForm'].validate(valid => {
        if (valid) {
          // updateTeam(this.submitForm).then(response => {
          //   this.$modal.msgSuccess('修改成功');
          //   this.open = false;
          //   this.getList();
          // });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(id, name) {
      // const id = row.id || this.ids;
      this.$confirm('是否确认删除团队"' + name + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return delTeam(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      console.log(queryParams, 'queryParams');
      this.$confirm('是否确认导出所有团队数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        console.log(queryParams, 'queryParams');
        this.download('/eqxm/team/export', { ...queryParams }, `team_${new Date().getTime()}.xlsx`);
        // return exportTeam(queryParams);
      });
      // .then(response => {
      //   console.log(response.msg);
      //   this.download(response.msg);
      // });
    },
    statusFormat(row, column) {
      return this.selectDictLabel(this.unitNameList, row.status);
    },
    // isimportantFormat(row, column) {
    //   return this.selectDictLabel(this.isimportants, row.isimportant);
    // },
    // researchtopicFormat(row, column) {
    //   let value = ""
    //   listOption({optionId:row.researchtopic}).then(response => {
    //     value = response.rows[0].optionName
    //     console.log(value)//输出"调研主题"
    //       return value;//界面上显示空
    //     });
    // },
    ispass(row, no) {
      row.ispass = no;
      ispass(row).then(response => {
        this.$modal.msgSuccess('修改成功');
        this.open = false;
        this.getList();
      });
    },
    commitExamine(row) {
      let comForm = {};
      comForm.id = row.id;
      comForm.status = '3';
      updateTeam(comForm).then(response => {
        this.$modal.msgSuccess('修改成功');
        this.open = false;
        this.getList();
      });
    },
    openclock(row) {
      /* let newform1={
			teamid:row.id,
			longitude:'120.470083',
			latitude:'36.250603'
		}
		
		addClockdetail(newform1).then(response => {
			
		}); */

      let newform = {
        teamid: row.id,
      };

      listClockdetail(newform).then(response => {
        for (let i = 0; i < response.total; i++) {
          let t = response.rows[i].createTime.indexOf('-');
          response.rows[i].createTime = response.rows[i].createTime.substring(
            t + 1,
            response.rows[i].createTime.length
          );
        }
        this.clockdetailList = response.rows;
        this.clockopen = true;
      });
    },
    imgStyle(val) {
      if (val != '' && val != undefined && val != null) {
        return val?.replace(
          /<img/g,
          '<img style="max-width: 100%!important;display: block;margin: 0 auto;"'
        );
      } else {
        console.log(val, '88899');
        return val;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.top-scroll {
  width: 100%;
  overflow-x: auto;
}
.top-scroll-content {
  /* 高度不设置的话滚动条出不来 */
  height: 10px;
}
.spec-dialog .el-dialog__body {
  padding: 3px 30px;
  overflow-y: auto;
  height: calc(100vh - 140px);
}
</style>
